import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import * as serviceWorker from './serviceWorker';
import { ConfigProvider } from 'antd';
import store from './model/index';
import App from './App';
import Report from './routers/Report';
import Login from './routers/Login';
import TokenAuth from './routers/System/Users/singleLogin';
import SkinProvider from './SkinProvider';
import zhCN from 'antd/es/locale/zh_CN';
import micro from 'src/micro';

micro.render = (props) => {
  const { container } = props;
  ReactDOM.render(
    <ConfigProvider locale={zhCN}>
      <Provider store={store}>
        <BrowserRouter basename={'/smp/'}>
          <Switch>
            <Route
              path='/'
              render={(props) => {
                return (
                  <Switch>
                    {/* <Route path='/login' {...props} component={Login} /> */}
                    {/* <Route path='/tokenAuth' {...props} component={TokenAuth} /> */}
                    {/* <Route
                        path='/report'
                        render={(props) => {
                          return <Report {...props} />;
                        }}
                      /> */}

                    <Route
                      path='/'
                      render={(props) => {
                        return <App {...props} />;
                      }}
                    />
                  </Switch>
                );
              }}
            />
          </Switch>
        </BrowserRouter>
      </Provider>
    </ConfigProvider>,
    container ? container.querySelector('#asterism') : document.getElementById('asterism')
  );
  micro.instanceContainer = container ? container.querySelector('#asterism') : document.getElementById('asterism');
};

if (!window.__POWERED_BY_QIANKUN__) {
  micro.render({});
} else {
  // runtime publicPath 主要解决的是微应用动态载入的 脚本、样式、图片 等地址不正确的问题
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
  console.log('!!!!!!', __webpack_public_path__);
}

export async function bootstrap() {
  micro.bootstrap();
}

export async function mount(props) {
  micro.mount(props);
}

export async function unmount() {
  micro.unmount();
}

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
